package com.kystar.muxplayer.protocol.code.get;

import com.kystar.muxplayer.model.Layer;
import com.kystar.muxplayer.model.LayerType;
import com.kystar.muxplayer.model.SourceType;
import com.kystar.muxplayer.protocol.CodeCmd;

public class CG8B_LayerState extends CodeCmd {
    private CG8B_LayerState(int typeId) {
        super(typeId,CODE_OK);
    }

    @Override
    public byte getCode() {
        return (byte) 0x8B;
    }

    public void loadLayer(Layer layer) {
        int activity = mResult[3]&0xFF;
        byte r1 = mResult[1];
        byte r2 = mResult[2];
        layer.setVisible((r1&0x01)==0x1);
        layer.setGlobal((r1&0x02)==0);
        layer.setOrder(r1>>2);
        layer.setSourceType(SourceType.values()[r2&0xFF]);
        layer.setSelected(activity==layer.getLayerType().id);
    }
    public void loadLayers(Layer[] layers) {
        int activity = mResult[1]&0xFF;
        for (int i = 0; i < 4; i++) {
            byte r1 = mResult[i*2+2];
            byte r2 = mResult[i*2+3];
            layers[i].setVisible((r1&0x01)==0x1);
            layers[i].setGlobal((r1&0x02)==0);
            layers[i].setOrder(r1>>2);
            layers[i].setSourceType(SourceType.values()[r2&0xFF]);
            layers[i].setSelected(activity==i+1);
        }
    }


    public static CG8B_LayerState createSingle(LayerType layerType) {
        return new CG8B_LayerState(layerType.id);
    }
    public static CG8B_LayerState createAll() {
        return new CG8B_LayerState(0);
    }
}
